/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.fed.sumo.traci.commands;

import com.google.common.collect.Iterables;
import org.eclipse.mosaic.fed.sumo.traci.complex.VehicleSubscriptionResult;
import org.eclipse.mosaic.fed.sumo.traci.junit.SumoRunner;
import org.eclipse.mosaic.rti.TIME;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

@RunWith(SumoRunner.class)
public class VehicleSetSignalsTest extends AbstractTraciCommandTest {

    @Test
    public void execute() throws Exception{
        // SETUP
        new VehicleSubscribe(traci.getTraciConnection()).execute(traci.getTraciConnection(), "1", 0L, 100 * TIME.SECOND);

        // PRE-ASSERT
        VehicleSubscriptionResult vehInfo =
                (VehicleSubscriptionResult) Iterables.getOnlyElement(simulateStep.execute(traci.getTraciConnection(), 6 * TIME.SECOND));
        assertEquals(0, vehInfo.signalsEncoded);

        // RUN
        new VehicleSetSignals().execute(traci.getTraciConnection(), "1", 1 << 2);

        // ASSERT
        vehInfo = (VehicleSubscriptionResult) Iterables.getOnlyElement(simulateStep.execute(traci.getTraciConnection(), 9 * TIME.SECOND));
        assertEquals(1 << 2, vehInfo.signalsEncoded);
    }
}
